package the.broccoli.et.infrastructure.persistent.repository;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Repository;
import the.broccoli.et.domain.model.UserEventStatistic;
import the.broccoli.et.domain.repository.EventTriggerRepository;
import the.broccoli.et.infrastructure.persistent.mapper.EventTriggerMapper;
import the.broccoli.et.infrastructure.persistent.model.EventTrigger;
import the.broccoli.et.interfaces.dto.EventTriggerCondition;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author lei.liu
 * @date 2021/7/20
 */
@Repository
public class EventTriggerRepositoryImpl implements EventTriggerRepository {

    @Resource
    private EventTriggerMapper eventTriggerMapper;

    @Override
    public int save(EventTrigger eventTrigger) {
        return eventTriggerMapper.insert(eventTrigger);
    }

    @Override
    public Page<EventTrigger> selectListPage(EventTriggerCondition condition) {
        PageHelper.startPage(condition.getPageNum(), condition.getPageSize());
        return eventTriggerMapper.selectListPage(condition);
    }

    @Override
    public List<UserEventStatistic> listUserEventStatistic(String eventCode, LocalDateTime start, LocalDateTime end) {
        return eventTriggerMapper.listUserEventStatistic(eventCode, start, end);
    }
}
